package lambadademo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

//无返回值无参数
interface Animals{
    void sleep();
}
//无返回值一个参数
interface Animal{
    void sleep(int a);
}
//无返回值多个参数
interface Dog{
    void sleep(int a,int b);
}
//有返回值无参数
interface Cat{
    int sleep();
}
//有返回值一个参数
interface Sheep{
    int  sleep(int a);
}
//有返回值多个参数
interface Duck{
    int sleep(int a,int b);
}
public class LambadaTest {
    public static void main(String[] args) {
        HashMap<String, Integer> map=new HashMap<>();
        map.put("hello",1);
        map.put("bit",1);
        map.put("seeYou",1);
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println("key:"+s+" "+"value:"+integer);
            }
        });
        System.out.println("========");
        map.forEach(((s, integer) -> System.out.println("key:"+s+" "+"value:"+integer)));
    }
    public static void main2(String[] args) {
        ArrayList<String> list=new ArrayList<>();
        list.add("hello");
        list.add("bit");
        list.add("2025");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        list.forEach(s -> {
            System.out.println(s);
        });
        System.out.println("============");
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        list.forEach(s -> {
            System.out.println(s);
        });
        System.out.println("=======================");
        list.sort(((o1, o2) -> o1.compareTo(o2)));
        list.forEach(s -> System.out.println(s));
    }
    public static void main1(String[] args) {
        //1.匿名内部类的对象调用重写的sleep方法
     Animals animals=new Animals() {
         @Override
         public void sleep() {
             System.out.println("i am sleeping");
         }
     };
     animals.sleep();
     //1.lambada表达式调用重写的sleep方法
        Animals animals1=()->{ System.out.println("i am sleeping");};
        animals1.sleep();
        //2.匿名内部类的对象调用重写的sleep方法
        Animal animal=new Animal() {
            @Override
            public void sleep(int a) {
                System.out.println(a);
            }
        };
        animal.sleep(12);
        //2.lambada表达式调用重写的sleep方法
        Animal animal1=(a)->{ System.out.println(a);};
        animal1.sleep(15);
        //3.匿名内部类的对象调用重写的sleep方法
        Dog dog=new Dog() {
            @Override
            public void sleep(int a, int b) {
                System.out.println(a+b);
            }
        };
        dog.sleep(15,2);
        //3.lambada表达式调用重写的sleep方法
        Dog dog1=(a,b)->{ System.out.println(a+b);};
        dog1.sleep(15,3);
        //4.匿名内部类的对象调用重写的sleep方法
        Cat cat=new Cat() {
            @Override
            public int sleep() {
                return 0;
            }
        };
        System.out.println( cat.sleep());
        //4.lambada表达式调用重写的sleep方法
        Cat cat1=()->{return 1;};
        System.out.println(cat1.sleep());
        //5.匿名内部类的对象调用重写的sleep方法
        Sheep sheep=new Sheep() {
            @Override
            public int sleep(int a) {
                return a;
            }
        };
        System.out.println(sheep.sleep(25));
        //5.lambada表达式调用重写的sleep方法
        Sheep sheep1=(a)->{return a;};
        System.out.println( sheep1.sleep(5));
        //6.匿名内部类的对象调用重写的sleep方法
        Duck duck=new Duck() {
            @Override
            public int sleep(int a, int b) {
                return a*b;
            }
        };
        System.out.println(duck.sleep(5,6));
        //6.lambada表达式调用重写的sleep方法
        Duck duck1=(a,b)->{return a*b;};
        System.out.println(duck1.sleep(2,3));
    }
}
